package com.ipad.ui.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ipad.R;
import com.ipad.bean.Product;

import java.util.List;

/**
 * Created by Administrator on 2018/12/5.
 */

public class DeliveryInfoAdapter extends RecyclerView.Adapter{
    List<Product> products;
    Context context;
    LayoutInflater inflater;

    public DeliveryInfoAdapter(List<Product> products, Context context) {
        this.products = products;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = inflater.inflate(R.layout.item_delivery_info_detail, parent, false);
        return new ContentView(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ContentView mholder = (ContentView) holder;
        mholder.code.setText(products.get(position).getProductVo().getErpCode());
        mholder.name.setText(products.get(position).getProductVo().getName());
        mholder.spec.setText(products.get(position).getProductVo().getSpec()+"、"+products.get(position).getProductVo().getModel());
        mholder.batch_num.setText(products.get(position).getBatchNum());
        mholder.value_date.setText(products.get(position).getValidDate());
        mholder.batch_num.setText(products.get(position).getBatchNum());
        mholder.unit.setText(products.get(position).getProductVo().getUnits());
        mholder.unit.setText(products.get(position).getProductVo().getUnits());
        mholder.num.setText(products.get(position).getOutQuantity().toString());
        mholder.price.setText("￥"+products.get(position).getProductVo().getPurchasePrice().toString());
        try {
//            mholder.producter.setText(products.get(position).getProductVo().getSupplierList().get(0).getName());
            mholder.producter.setText(products.get(position).getProductVo().getSupplierNames());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public int getItemCount() {
        return products.size();
    }


    public static class ContentView extends RecyclerView.ViewHolder{
        TextView code;
        TextView name;
        TextView spec;
        TextView batch_num;
        TextView value_date;
        TextView unit;
        TextView num;
        TextView price;
        TextView producter;
        public ContentView(View itemView) {
            super(itemView);
            code = itemView.findViewById(R.id.item_delivery_detail_code);
            name = itemView.findViewById(R.id.item_delivery_detail_name);
            spec = itemView.findViewById(R.id.item_delivery_detail_spec);
            batch_num = itemView.findViewById(R.id.item_delivery_detail_batch_num);
            value_date = itemView.findViewById(R.id.item_delivery_detail_value_date);
            unit = itemView.findViewById(R.id.item_delivery_detail_unit);
            price = itemView.findViewById(R.id.item_delivery_detail_price);
            num = itemView.findViewById(R.id.item_delivery_detail_num);
            producter = itemView.findViewById(R.id.item_delivery_detail_producter);
        }
    }
}
